package com.luobo.shiro.config;

import com.luobo.shiro.bean.LocalUser;
import com.luobo.shiro.util.JWTUtil;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.eis.SessionIdGenerator;

import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

/**
 * @author : AnWen
 * @version :1.0
 * @email : anwen375@qq.com
 * @since : 2020/2/21 14:49
 */
public class MySessionIdGenerator implements SessionIdGenerator {

    public MySessionIdGenerator() {
    }

    public Serializable generateId(Session session) {
        String ip = "0:0:0:0:0:0:0:1".equals(session.getHost()) ? "127.0.0.1" : session.getHost();
        String username = LocalUser.get();
        return JWTUtil.createSessionId(ip,username);
    }
}
